package feng.demo.entity;

import com.fasterxml.jackson.databind.ObjectMapper;
import feng.demo.utils.PackJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class XJson {
    Logger logger=LoggerFactory.getLogger(PackJson.class);
    ObjectMapper objectMapper=new ObjectMapper();
    private Integer code;
    private String msg;
   private Object data;

    public XJson() {
    }
    public XJson(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Object getData() {
        return data;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(Object data) {
        this.data = data;
    }


    @Override
    public String toString() {
        Map<String,Object> map=new HashMap<>();
        map.put("code",code);
        map.put("msg",msg);
        map.put("data",data);
        String s="";
        try {
            //把map转成json字符串
            s = objectMapper.writeValueAsString(map);
        }catch (Exception e){
            logger.error(e.getMessage());
        }
        logger.debug("json="+s);
        return s;
        }
}
